package com.xuan.core.service.cul.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xuan.core.dto.cul.PageDto;
import com.xuan.core.mapper.cul.CulSixGuaMapper;
import com.xuan.core.pojo.cul.CulSixGua;
import com.xuan.core.service.cul.CulSixGuaService;
import com.xuan.core.service.sys.SysCountService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 六十四卦Impl
 */
@Service
public class CulSixGuaServiceImpl extends ServiceImpl<CulSixGuaMapper, CulSixGua> implements CulSixGuaService {

    @Autowired
    private SysCountService sysCountService; // 系统统计Service

//********************************************************************************************************************************

    /**
     * 分页查询
     *
     * @param dto 分页查询数据接收类
     * @return 分页数据
     */
    @Override
    public Page<CulSixGua> page(PageDto dto) {

        // 1、分页校验
        dto.checkPage();

        // 2、构造查询条件
        LambdaQueryWrapper<CulSixGua> qw = new LambdaQueryWrapper<>();
        qw.like(StringUtils.isNotEmpty(dto.getQueryData()), CulSixGua::getName, dto.getQueryData()); // 查询条件
        qw.orderByAsc(CulSixGua::getId); // 按照id升序

        // 3、分页查询
        Page<CulSixGua> page = new Page<>(dto.getPage(), dto.getPageSize());
        this.page(page, qw);

        // 4、增加1次总访问数
        sysCountService.saveVisitsNumber();

        // 5、返回结果
        return page;
    }


}
